package service;

import com.example.demo.InitSocketServlet;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.List;

public class SendCmdService {
    //private List<Socket> socketList = InitSocketServlet.socketList;

    public static void sendCmd(String cmd)  {
        for(Socket socket:InitSocketServlet.socketList){
            DataOutputStream dataOutputStream = null;
            try {
                dataOutputStream = new DataOutputStream(socket.getOutputStream());
                dataOutputStream.writeUTF(cmd);
                dataOutputStream.flush();
            } catch (IOException e) {
                InitSocketServlet.socketList.remove(socket);
            }
        }
    }

}
